package git.soulbgm.handle;

import git.soulbgm.common.Constants;
import git.soulbgm.pojo.DataSegmentSummaryInfo;
import git.soulbgm.service.DataSegmentSummaryInfoService;
import org.springframework.kafka.annotation.KafkaHandler;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Collections;

/**
 * 数据包接收序列句柄
 *
 * @author SoulBGM
 * @date 2024-09-23
 */
@Component
@KafkaListener(topics = Constants.TOPIC_DATA_SEGMENT_SUMMARY)
public class DataSegmentSummaryInfoHandle {

    private final DataSegmentSummaryInfoService service;

    public DataSegmentSummaryInfoHandle(DataSegmentSummaryInfoService service) {
        this.service = service;
    }

    @KafkaHandler
    public void listen(DataSegmentSummaryInfo sequence) {
        try {
            service.saveBatch(Collections.singletonList(sequence));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
